//
//  YJCardBottomView.m
//  YJB
//
//  Created by YJB on 16/10/14.
//  Copyright © 2016年 YJB. All rights reserved.
//

#import "YJCardBottomView.h"
#import "Masonry.h"

@interface YJCardBottomView ()

@property(nonatomic,strong)UIButton  *callBtn;
@property(nonatomic,strong)UIButton  *moreItem;
@end

@implementation YJCardBottomView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self cardAssistant];
        self.backgroundColor = WHITECOLOR;
    }
    return self;
}

- (UIButton *)cardAssistant
{
    if (_cardAssistant == nil)
    {
        _cardAssistant = [[UIButton alloc]init];
        [_cardAssistant setTitle:@"助手信息" forState:UIControlStateNormal];
        _cardAssistant.titleLabel.font = FONT(17);
        [_cardAssistant setTitleColor:kUIColorFromRGB(0x333333) forState:UIControlStateNormal];
        [_cardAssistant addTarget:self action:@selector(cardAssistantBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cardAssistant];
        [_cardAssistant mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.moreItem.mas_right).offset(1);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.right.mas_equalTo(self.callBtn.mas_left).offset(-0.5);
        }];
        UIImageView *sanView = [[UIImageView alloc]init];
        sanView.image = Image(@"shrink_2_icon");
        [_cardAssistant addSubview:sanView];
        [sanView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.mas_equalTo(0);
            make.width.height.mas_equalTo(10);
        }];
        
        //上分割线
        UIView *topLineView = [[UIView alloc]init];
        topLineView.backgroundColor = [kUIColorFromRGB(0x999999) colorWithAlphaComponent:0.5];
        [self addSubview:topLineView];
        [topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.top.equalTo(@0);
            make.right.equalTo(@0);
            make.height.equalTo(@0.5);
        }];
        //下分割线
        UIView *bottomLineView = [[UIView alloc]init];
        bottomLineView.backgroundColor = [kUIColorFromRGB(0x999999) colorWithAlphaComponent:0.5];
        [self addSubview:bottomLineView];
        [bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@0);
            make.bottom.equalTo(@0);
            make.right.equalTo(@0);
            make.height.equalTo(@0.5);
        }];
    }
    return _cardAssistant;
}

-(UIButton *)callBtn
{
    if (_callBtn == nil)
    {
        UIButton *callBtn = [[UIButton alloc]init];

        callBtn.titleLabel.font = FONT(17);
        [callBtn setTitleColor:kUIColorFromRGB(0x333333) forState:UIControlStateNormal];
        [callBtn addTarget:self action:@selector(callBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [callBtn setTitle:@"免费电话" forState:UIControlStateNormal];
        [self addSubview:callBtn];
        _callBtn = callBtn;
        [_callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(120);
        }];
        
        UIView *line = [[UIView alloc]init];
        line.backgroundColor = kUIColorFromRGB(0xe0e0e0);
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(0.5);
            make.right.mas_equalTo(callBtn.mas_left);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _callBtn;
}

- (UIButton *)moreItem
{
    if (_moreItem == nil)
    {
        _moreItem = [[UIButton alloc]init];
        [_moreItem setImage:Image(@"key_hl") forState:UIControlStateNormal];
        [_moreItem addTarget:self action:@selector(swithBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_moreItem];
        [_moreItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(50);
            make.top.mas_equalTo(5);
        }];
        
        UIView *line = [[UIView alloc]init];
        line.backgroundColor = kUIColorFromRGB(0xe0e0e0);
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.width.mas_equalTo(0.5);
            make.left.mas_equalTo(_moreItem.mas_right);
            make.bottom.mas_equalTo(0);
        }];
        
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.contentMode = UIViewContentModeBottom;
        imageView.image = Image(@"shrink_icon");
        [self addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.right.mas_equalTo(_moreItem.mas_right);
            make.bottom.mas_equalTo(_moreItem.mas_top).offset(10);
            make.top.mas_equalTo(0);
        }];
    }
    return _moreItem;
}

- (void)swithBtnClick:(UIButton *)button
{
    if (self.toolBarClickBlock)
        self.toolBarClickBlock(YJCardBottomViewButtonTypeSwitch);
}

- (void)cardAssistantBtnClick:(UIButton *)button
{
    if (self.toolBarClickBlock)
        self.toolBarClickBlock(YJCardBottomViewButtonTypeAssistant);
}

- (void)callBtnClick
{
    if (self.toolBarClickBlock)
        self.toolBarClickBlock(YJCardBottomViewButtonTypeCall);
}

@end
